package com.whfc.iot.fse.crane.processor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.whfc.iot.fse.crane.entity.TwConst.*;

/**
 * @Description:
 * @author: xugcheng
 * @version: 1.0
 * @date: 2019/8/29 15:13
 */
@Component
public class TwUpMsgProcessorFactory {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private TwUpMsgProcessorRegister processorRegister;

    @Autowired
    private TwUpMsgProcessorDownline processorDownline;

    @Autowired
    private TwUpMsgProcessorHeartbeat processorHeartbeat;

    @Autowired
    private TwUpMsgProcessorParam processorParam;

    @Autowired
    private TwUpMsgProcessorRealData processorRealData;

    @Autowired
    private TwUpMsgProcessorWorkCycle processorWorkCycle;

    @Autowired
    private TwUpMsgProcessorTipAlarmData processorTipAlarmData;

    /**
     * 获取消息处理器
     *
     * @param cmd
     * @return
     */
    public TwUpMsgProcessor getMsgProcessor(int cmd) {
        TwUpMsgProcessor processor = null;
        switch (cmd) {
//            case TW_CMD_REGISTER:
//                processor = processorRegister;
//                break;
//            case TW_CMD_DOWNLINE:
//                processor = processorDownline;
//                break;
//            case TW_CMD_HEARTBEAT:
//                processor = processorHeartbeat;
//                break;
            case TW_CMD_PARAM:
                processor = processorParam;
                break;
            case TW_CMD_REALDATA:
                processor = processorRealData;
                break;
            case TW_CMD_WORKCYCLEDATA:
                processor = processorWorkCycle;
                break;
//            case TW_CMD_TIPALARMDATA:
//                processor = processorTipAlarmData;
//                break;
            default:
                logger.info("无法解析的指令,cmd:{}", cmd);
        }
        return processor;
    }
}
